package ru.papergames.web.blines.battle.network.serverpackets;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.papergames.common.form.PcPlayerForm;
import ru.papergames.web.cache.PlayersManager;

/**
 * User: atroshanin
 * Date: 15.11.2010
 * Time: 13:51:23
 */
public class FlashUserConnected extends WebServerServerPacket {

    private static Log log = LogFactory.getLog(FlashUserConnected.class);

    private int playerId;

    @Override
    protected void readImpl() {
        playerId = readD();
    }

    @Override
    protected void runImpl() {
        log.info("Flash user connected[playerId: " + playerId);
        getClient().getConnectionHolder().incUsersCount();
        PcPlayerForm player = PlayersManager.getInstance().getActivePlayer(playerId);
        if (player == null) {
            return;
        }
        player.setConnectedToBattleServer();
    }

    @Override
    public String getType() {
        return "[s] FlashUserConnected [" + FLASH_USER_CONNECTED_PACKET_ID + "]";
    }
}
